package org.ehe.area.controller;

import jakarta.annotation.Resource;
import org.ehe.area.domain.City;
import org.ehe.area.domain.Province;
import org.ehe.area.domain.Town;
import org.ehe.area.service.AddressService;
import org.ehe.common.core.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 省市区信息
 * @author :zhangnn
 * @className :AddressController
 * @description: TODO
 * @date 2025-07-29 10:23:32
 */
@RestController
@RequestMapping("/api/address")
public class AddressController {
    @Resource
    private AddressService addressService;

    /**
     * 获取所有省份
     */
    @GetMapping("/provinces")
    public R<List<Province>> getAllProvinces() {
        List<Province> provinces = addressService.getAllProvinces();
        return R.ok(provinces);
    }

    /**
     * 根据省份编码获取城市
     */
    @GetMapping("/cities/{provinceCode}")
    public R<List<City>> getCitiesByProvinceCode(@PathVariable String provinceCode) {
        List<City> cities = addressService.getCitiesByProvinceCode(provinceCode);
        return R.ok(cities);
    }

    /**
     * 根据城市编码获取区县
     */
    @GetMapping("/towns/{cityCode}")
    public R<List<Town>> getTownsByCityCode(@PathVariable String cityCode) {
        List<Town> towns = addressService.getTownsByCityCode(cityCode);
        return R.ok(towns);
    }
}
